# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def minDiffInBST(self, root: TreeNode) -> int:
        ret=1000000
        now=-1000000
        def traverse(node):
            nonlocal ret,now
            if not node:
                 return 
            traverse(node.left)
            ret=min(ret,node.val-now)
            now=node.val
            traverse(node.right)
        traverse(root)
        return ret

# 执行用时：
# 40 ms
# , 在所有 Python3 提交中击败了
# 70.68%
# 的用户
# 内存消耗：
# 14.9 MB
# , 在所有 Python3 提交中击败了
# 52.47%
# 的用户